import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:simple_app/accept_list.dart';
import 'package:simple_app/friend_list.dart';
import 'package:simple_app/message_list.dart';

class TabListRouteArgs {
  final String name;
  TabListRouteArgs({required this.name});
}

//TAB页
class TabList extends StatefulWidget {
  const TabList({Key? key}) : super(key: key);
  @override
  State<StatefulWidget> createState() => _TabList();
}

class _TabList extends State<TabList> {
  final List<BottomNavigationBarItem> tabBtn = const [
    BottomNavigationBarItem(icon: Icon(Icons.message), label: '消息列表'),
    BottomNavigationBarItem(icon: Icon(Icons.people), label: '好友列表'),
    BottomNavigationBarItem(icon: Icon(Icons.person_add), label: '申请列表'),
  ];
  var currentIndex = 0;
  final List<Widget> page = const [
    MessageListPage(),
    FriendsListPage(),
    AcceptListPage()
  ];
  late Widget currentPage = page[0];

  String nickname = '';

  @override
  Widget build(BuildContext context) {
    var args = ModalRoute.of(context)!.settings.arguments as TabListRouteArgs?;
    if (args.runtimeType != Null) {
      nickname = args!.name;
    }

    return Scaffold(
      appBar: AppBar(
        actions: [
          if (currentIndex == 2)
            GestureDetector(
              onTap: () {
                //搜索按钮，进入搜索好友功能页
                Navigator.pushNamed(context, '/friend_search');
              },
              child: const Icon(Icons.search),
            )
        ],
        title: Text(nickname),
        // toolbarHeight: 0,
      ),
      body: currentPage,
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: currentIndex,
        items: tabBtn,
        onTap: (index) {
          setState(() {
            currentIndex = index;
            currentPage = page[currentIndex];
          });
        },
      ),
    );
  }
}
